<?php

namespace common\models\wechat;

use common\models\CommonModel;
use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "wechat_menus".
 *
 * @property string $id
 * @property string $wid
 * @property string $menuid
 * @property integer $type
 * @property string $title
 * @property integer $sex
 * @property integer $group_id
 * @property integer $client_platform_type
 * @property string $area
 * @property string $data
 * @property integer $status
 * @property string $createtime
 * @property integer $isdeleted
 */
class WechatMenus extends ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '微信菜单',      //用于修改了什么的显示
        'mainfield' => 'title',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    public $matchruletext = '';


    const DELETE = -1;
    const DEFAULT = 0;
    public static $deleted = [
        self::DEFAULT => '起效',
        self::DELETE => '删除',
    ];

    const TYPE_DEFAULT = 1;
    const TYPE_HISTORY = 2;
    const TYPE_GEXING = 3;
    public static $types = [
        self::TYPE_DEFAULT => '默认',
        self::TYPE_HISTORY => '默认（历史）',
        self::TYPE_GEXING => '个性化菜单',
    ];

    const STATUS_LINE = 1;
    const STATUS_OFF = 2;
    public static $statues = [
        self::STATUS_LINE => '在线生效',
        self::STATUS_OFF => '未生效',
    ];


    public static $sexs = [
        '不限','男','女'
    ];


    public static $platform = [
        '不限','IOS(苹果)','Android(安卓)','Others(其他)'
    ];




    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'wechat_menus';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['wid', 'menuid', 'type', 'sex', 'group_id', 'client_platform_type', 'status', 'createtime', 'isdeleted'], 'integer'],
            [['data'], 'string'],
            [['title'], 'string', 'max' => 30],
            [['area'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'wid' => '公众号id',
            'menuid' => '菜单i',
            'type' => '类型',
            'title' => '名称',
            'sex' => '匹配性别',
            'group_id' => '匹配组别',
            'client_platform_type' => '匹配终端',
            'area' => '匹配地区',
            'data' => '菜单数据',
            'status' => '状态',
            'createtime' => '创建时间',
            'isdeleted' => '是否删除',
            'matchruletext' => '匹配规则',
        ];
    }


    public function beforeSave($insert)
    {
        if($this->isNewRecord){
            $this->createtime = time();
        }
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }



}
